package strategy

import (
	"fmt"
	"github.com/xuri/excelize/v2"
)

type DefaultStyleStrategy struct {
}

func (s *DefaultStyleStrategy) ApplyHeaderStyle(f *excelize.File, sheet string, headers []string) error {
	styleID, _ := f.NewStyle(&excelize.Style{
		Font: &excelize.Font{Bold: true},
	})
	endCol, _ := excelize.ColumnNumberToName(len(headers))
	return f.SetCellStyle(sheet, "A1", endCol+"1", styleID)
}

func (s *DefaultStyleStrategy) ApplyBodyStyle(f *excelize.File, sheet string, data [][]interface{}) error {
	styleID, _ := f.NewStyle(&excelize.Style{
		Border: []excelize.Border{
			{Type: "left", Style: 1, Color: "#000000"},
			{Type: "right", Style: 1, Color: "#000000"},
		},
	})
	startRow := 2
	endCol, _ := excelize.ColumnNumberToName(len(data[0]))
	endRow := startRow + len(data) - 1
	return f.SetCellStyle(sheet, fmt.Sprintf("A%d", startRow), fmt.Sprintf("%s%d", endCol, endRow), styleID)
}
